//
//  AvatarsView.m
//  Flava
//
//  Created by Ug-Code on 13-8-12.
//  Copyright (c) 2013年 UgCode. All rights reserved.
//

#import "AvatarsView.h"

@implementation AvatarsView

@synthesize
image = _image,
avatarsImageView = _avatarsImageView,
avatarsMaskView = _avatarsMaskView;

/** 工厂方法创建原型用户头像, 头像直径37 */
+ (AvatarsView *)navRoundAvatarsView
{
	AvatarsView *avatarsView = [[AvatarsView alloc] init];
	avatarsView.frame = CGRectMake(0, 0, 37, 37);
	[avatarsView setImage:[UIImage imageNamed:@"profile_dummy2.png"]];
	//-- 裁剪成圆形
	avatarsView.layer.masksToBounds = YES;
	avatarsView.layer.cornerRadius = 18.5;
	//--用图片遮盖成圆形
//	[avatarsView setMaskImage:[UIImage imageNamed:@"navigation_bar_mask.png"]];
	return avatarsView;
}

/** 工厂方法, 创建方形头像 */
+ (AvatarsView *)leftSquareAvatarsView
{
	AvatarsView *avatarsView = [[AvatarsView alloc] init];
	avatarsView.frame = CGRectMake(15, 110, 50, 50);
	[avatarsView setImage:[UIImage imageNamed:@"profile_dummy2.png"]];
	[avatarsView setMaskImage:[UIImage imageNamed:@"thumbnail_mask5.png"]];
	[avatarsView setMaskFrame:CGRectMake(-5, -5, 60, 60)];
	return avatarsView;
}

- (id)init
{
    self = [super init];
    if (self) {
        _avatarsImageView = [[UIImageView alloc] init];
		_avatarsMaskView = [[UIImageView alloc] init];
		[self addSubview:_avatarsMaskView];
		[self addSubview:_avatarsImageView];
    }
    return self;
}

- (void)setImage:(UIImage *)image
{
	_avatarsImageView.image = image;
}

- (void)setMaskImage:(UIImage *)image
{
	_avatarsMaskView.image = image;
}

- (void)setFrame:(CGRect)frame
{
	[super setFrame:frame];
	CGRect rect = CGRectMake(0, 0, frame.size.width, frame.size.height);
	_avatarsImageView.frame = rect;
	_avatarsMaskView.frame = rect;
}

- (void)setMaskFrame:(CGRect)frame
{
	_avatarsMaskView.frame = frame;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
